package de.fuberlin.inf.alp2;

import java.util.LinkedList;
import java.util.List;

public class Rectangle implements Polygon {
	private Point lowerLeft;
	private Point upperRight;
	
	public Rectangle(Point p2){
		this(new Point(0,0), p2);
	}
	
	public Rectangle(Point p1, Point p2){
		this.lowerLeft = new Point((Math.min(p1.getX(), p2.getX())),
				(Math.min(p1.getY(), p2.getY())));
		this.upperRight = new Point((Math.max(p1.getX(), p2.getX())),
				(Math.max(p1.getY(), p2.getY())));;
	}

	@Override
	public boolean addPoint(Point p) throws Exception {
		throw new Exception("Rectangles only consists of two points.");
	}

	@Override
	public Point center() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isPolygon() {
		return true;
	}

	@Override
	public double perimeter() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void shift(int dx, int dy) {
		// TODO Auto-generated method stub

	}

	public Point getLowerLeft() {
		return lowerLeft;
	}

	public void setLowerLeft(Point lowerLeft) {
		this.lowerLeft = lowerLeft;
	}

	public Point getUpperRight() {
		return upperRight;
	}

	public void setUpperRight(Point upperRight) {
		this.upperRight = upperRight;
	}

	@Override
	public List<Point> getPoints() {
		LinkedList<Point> ret = new LinkedList<Point>();
		ret.add(this.lowerLeft);
		ret.add(new Point(this.lowerLeft.getX(), this.upperRight.getY()));
		ret.add(this.upperRight);
		ret.add(new Point(this.upperRight.getX(), this.lowerLeft.getY()));
		return ret;
	}

}
